﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ZOIL.DataModel;
using System.IO;
using System.Reflection;

namespace ZOIL.DataBackend.Server
{
    /// <summary>
    /// Interaction logic for ServerView.xaml
    /// </summary>
    public partial class ServerView : Window
    {
        public ServerView()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(ServerView_Loaded);
            Closing += new System.ComponentModel.CancelEventHandler(ServerView_Closing);
            Closed += new EventHandler(ServerView_Closed);
        }

        void ServerView_Closed(object sender, EventArgs e)
        {
            Server s = Server.getInstance();
            s.SaveConfig();
            s.CloseConfigContainer();
        }

        void ServerView_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Server s = Server.getInstance();
            foreach (DatabaseConfiguration config in s.Databases)
            {
                if (config.Status == DatabaseStatus.Running)
                {
                    e.Cancel = true;
                    MessageBox.Show("Please stop all running databases, before closing.");
                    break;
                }
            }
        }

        void ServerView_Loaded(object sender, RoutedEventArgs e)
        {
            Server s = Server.getInstance();
            ServerViewModel svm = new ServerViewModel();
            svm.Model = s;
            this.DataContext = svm;

            //ZOIL.Library.Behaviours.KeyBinding b = new ZOIL.Library.Behaviours.KeyBinding();
            //List<ZOIL.Library.Behaviours.KeyBinding> bindings = new List<ZOIL.Library.Behaviours.KeyBinding>();
            //bindings.Add(b);

            //KeyboardBehaviour.SetKeyBindings(toolbar, bindings);

        }
    }
}
